
$(function(){
	//点击弹出搜索
	$(document).on("click",".ans_search_btn",function()
	{
		doctor_open_search();
    });
    //关闭搜索框
    $(document).on("click",".ans_close3",function()
	{
		doctor_close_search();
    });
    //点击搜索
    $(document).on("click",".ans_rw3",function()
	{
		doctor_search(this);
    });
    //关闭搜索详情
    $(document).on("click",".ans_close4",function()
	{
		doctor_open_search_out_close();
    });
});

//开始搜索
var searchDate = [];
function doctor_search(obj)
{
    var keyword = $.trim($('#searchInp').val());
    if(keyword == '')
    {
        outjs_openblock('请填写搜索关链词！');
        return false;
    }
    else
    {
        $(".ast_nolist").hide();
        searchDate = [];
        $("#searchResult").empty();
        $("#searchResult").show();
        layui.use('flow', function(){
            var $ = layui.jquery; //不用额外加载jQuery，flow模块本身是有依赖jQuery的，直接用即可。
            var flow = layui.flow;
            var tIndex = 1;
            flow.load({
                elem: '#searchResult', //指定列表容器
                scrollElem: '#searchResult',
                isAuto: true,
                mb: 200,
                done: function(page, next){ //到达临界点（默认滚动触发），触发下一页
                    var lis = [];
                    $.get("http://www.jxapp.com:8080/search?current=" + page +  "&keyword=" + keyword + "&size=20", function(res){
                        //假设你的列表返回在data集合中
                        layui.each(res.data.records, function(index, item){
                            lis.push('<ul class="ast_ul"><li onclick="detail('+ tIndex +');">'+ tIndex + ". " +item.content +'</li></ul>');
                            searchDate.push(item.sourceMap);
                            tIndex++;
                        });
                        console.log(res);

                        //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                        //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                        next(lis.join(''), page < res.data.pages);
                    });
                }
            });
        });
    }
}

/**
 * 查看查询详情
 * @param index
 */
function detail(index) {
    doctor_open_search_out();
    //追加内容
    var map = searchDate[index-1];
    var html = "";
    objToStrMap(map).forEach(function(value,key){
        html += "<div>"+ key + "：" + value + "</div>"
    });
    doctor_open_search_html('' , html);
}

